package site.yunnong.atvris.portal.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import site.yunnong.atvris.common.api.Page;
import site.yunnong.atvris.common.api.ResultVO;
import site.yunnong.atvris.portal.service.EsService;
import site.yunnong.atvris.service.EsUserService;
import site.yunnong.atvris.service.EsVideoService;
import site.yunnong.atvris.common.dto.SearchUserParam;
import site.yunnong.atvris.common.dto.SearchVideoParam;
import site.yunnong.atvris.service.vo.SearchVideoConditionVO;
import site.yunnong.atvris.service.vo.UserCardVO;
import site.yunnong.atvris.service.vo.VideoCardVO;

import javax.annotation.Resource;

/**
 * @author zjh
 * @date 2021/8/19 11:56
 */
@Api("es检索")
@RequestMapping("/es")
@RestController
public class ElasticSearchController {
    
    @Resource
    private EsService esService;
    @Resource
    private EsVideoService esVideoService;
    @Resource
    private EsUserService esUserService;
    
    @ApiOperation("获取视频查询系列条件")
    @GetMapping("/search-video-condition")
    public ResultVO getSearchVideoCondition() {
        SearchVideoConditionVO result = esService.getSearchVideoCondition();
        return new ResultVO().success(result);
    }
    
    @ApiOperation("条件搜索视频")
    @PostMapping("/search-video")
    public ResultVO searchVideo(@RequestBody SearchVideoParam param) {
        Page<VideoCardVO> result = esVideoService.search(param);
        return new ResultVO().success(result);
    }

    @ApiOperation("条件搜索用户")
    @PostMapping("/search-user")
    public ResultVO searchUser(@RequestBody SearchUserParam param) {
        Page<UserCardVO> result = esUserService.search(param);
        return new ResultVO().success(result);
    }
    
    @ApiOperation("导入所有视频数据")
    @PostMapping("/import-all-video")
    public ResultVO importAllVideo() {
        int count = esVideoService.importAll();
        return new ResultVO().success(count);
    }

    @ApiOperation("导入所有用户数据")
    @PostMapping("/import-all-user")
    public ResultVO importAllUser() {
        int count = esUserService.importAll();
        return new ResultVO().success(count);
    }
}
